<template>
  <van-row class="article_wrap">
    <van-list
      v-model="loading"
      :finished="finished"
      :immediate-check="false"
      :offset="10"
      @load="onLoad"
    >
      <div class="item_wrap">
        <div v-for="(item, index) in list" :key="index" class="item_task">
          <div :span="24" class="task_top">
            <van-col>
              <van-image :src="item.cover_pic" cover class="img_item" />
            </van-col>
            <van-col class="sign-total">
              <span>{{ item.article_content }}</span>
            </van-col>
          </div>
          <div class="card_bottom">
            <div class="introduce_left">
              <span class="liulan_sty">{{ item.create_time }}</span>
              <span class="liulan_sty">阅读数</span>
              <span>{{ item.view_num }}</span>
              <span class="dianzan_sty">点赞</span>
              <span>{{ item.zan_num }}</span>
            </div>
            <div class="introduce_right" @click="deleteArticle(index, item)">
              <van-icon name="delete" class="delete_icon" />
              <span class="delete_text">删除</span>
            </div>
          </div>
        </div>
      </div>
    </van-list>
    <div v-if="list.length <= 0" class="no-data">
      <img :src="require('@/assets/images/empty.jpeg')" alt="">
      <div class="no-title">哎呦~还没有呢, 先去看看其他吧</div>
    </div>
  </van-row>
</template>

<script>
import api from '@/api/car'
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      params: {
        page_num: 1,
        page_size: 10
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    deleteArticle(index, item) {
      this.$dialog.confirm({
        title: '提示',
        message: '您确定删除吗？'
      })
        .then(() => {
          const parsms = {
            article_id: item.article_id
          }
          api.deleteArticle(parsms)
            .then(res => {
              if (res.code === 200) {
                this.$toast.success('删除成功')
                this.list.splice(index, 1)
              }
            })
        })
        .catch(() => {})
    },
    onLoad() {
      this.params.page_num++
      this.getList()
    },
    getList() {
      this.$toast.loading({
        forbidClick: true,
        mask: false,
        duration: 0,
        message: '加载中...'
      })
      api.userArticleList(this.params).then((res) => {
        this.$toast.clear()
        if (parseInt(res.code) === 200) {
          res.result.forEach(el => {
            el.cover_pic = this.handle_pic(el.cover_pic)
          })
          this.list = [...this.list, ...res.result]
          if (this.params.page_size > res.result.length) {
            this.finished = true
          } else {
            this.finished = false
          }
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.article_wrap {
  .item_wrap{
    padding: 0 16px 80px;
    .item_task {
      box-shadow: 0px 4px 8px 4px rgba(240, 240, 240, 1);
      border-radius: 10px;
      margin-top: 10px;
      padding-bottom: 5px;
      .task_top {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding: 15px 14px 0px;
        .img_item {
          width: 80px;
          height: 80px;
          margin-right: 10px;
          /deep/ img{
            border-radius: 5px;
          }
        }
        .sign-total {
          display: flex;
          flex-direction: column;
          height: 80px;
          span {
            font-size: 14px;
            color: #333;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 4;
            overflow: hidden;
            line-height: 1.5;
          }
        }
      }
      .operation {
        display: flex;
        justify-content: flex-end;
        font-size: 12px;
        padding: 10px 16px;
        span {
          margin-left: 5px;
        }
        .item {
          margin-left: 10px;
        }
        .item.active {
          color: #E60039;
        }
      }
      .task_bottom {
        padding: 0 14px;
        margin-top: 12.5px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .icon_s {
          font-size: 14px;
          font-weight: 400;
          color: #666666;
          margin-right: 5px;
        }
        .number_s {
          font-size: 10px;
          font-weight: 400;
          color: #666666;
        }
      }
      .card_bottom {
        display: flex;
        align-items: center;
        justify-content: flex;
        background-color: #fff;
        border-radius: 0 0 12.5px 12.5px;
        margin-top: 10px;
        .introduce_left {
          display: flex;
          align-items: center;
          padding-left: 15px;
          width: 100%;
          line-height: 20px;
          .liulan_sty {
            color: #999;
            font-size: 10px;
            margin-right: 5px;
          }
          .dianzan_sty {
            color: #999;
            font-size: 10px;
            margin: 0 5px 0 10px;
          }
          span {
            color: #999;
            font-size: 12px;
          }
        }
        .introduce_right{
          display: flex;
          align-items: center;
          justify-content: flex-end;
          padding-right: 15px;
          width: 50%;
          .delete_icon{
            margin-right: 5px;
            color: #999;
            font-size: 12px;
          }
          .delete_text{
            color: #999;
            font-size: 10px;
          }
        }
      }
    }
  }
  .no-data {
    width: 80%;
    margin: 0 auto;
    height: auto;
    img {
      width: 40%;
      margin: 30px auto 0;
      height: 100%;
      display: block;
    }
    .no-title {
      width: 100%;
      font-size: 14px;
      color: #999999;
      text-align: center;
    }
  }
}
</style>
